/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.WebIDE.ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author huy
 */
@Entity
@Table(name = "topics")
@NamedQueries({@NamedQuery(name = "Topics.findAll", query = "SELECT t FROM Topics t"), @NamedQuery(name = "Topics.findById", query = "SELECT t FROM Topics t WHERE t.id = :id"), @NamedQuery(name = "Topics.findByTitle", query = "SELECT t FROM Topics t WHERE t.title = :title")})
public class Topics implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "title")
    private String title;
    @JoinColumn(name = "user_name", referencedColumnName = "user_name")
    @ManyToOne(fetch = FetchType.EAGER)
    private Users userName;
    @OneToMany(mappedBy = "topicId", fetch = FetchType.EAGER)
    private Collection<Replies> repliesCollection;

    public Topics() {
    }

    public Topics(Integer id) {
        this.id = id;
    }

    public Topics(Integer id, String title) {
        this.id = id;
        this.title = title;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Users getUserName() {
        return userName;
    }

    public void setUserName(Users userName) {
        this.userName = userName;
    }

    public Collection<Replies> getRepliesCollection() {
        return repliesCollection;
    }

    public void setRepliesCollection(Collection<Replies> repliesCollection) {
        this.repliesCollection = repliesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Topics)) {
            return false;
        }
        Topics other = (Topics) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.WebIDE.ejb.entities.Topics[id=" + id + "]";
    }

}
